package cn.suimg.neo4j.repository;

import cn.suimg.neo4j.graph.SingerGraph;
import cn.suimg.neo4j.relationship.SingRelationship;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SingRelationshipRepository extends Neo4jRepository<SingRelationship, Long> {

    @Query("match r = (singerGraph:歌手 {singerId:{0}}) -[rel:演唱] -> (songGraph:歌曲{songId:{1}}) return distinct r")
    SingRelationship findBySingerIdAndSongId(Integer singerId,Integer songId);

    @Query("match (singerGraph:歌手 {singerId:{singerId}}) - [singRel:演唱] -> (songGraph:歌曲 {songId:{songId}}) return count(singRel) >= 1")
    boolean checkSingRelationshipExistBySingerIdAndSongId(@Param("singerId") Integer singerId, @Param("songId") Integer songId);

    @Query("match r = (singerGraph:歌手) - [rel:演唱] -> (songGraph:歌曲{songId:{songId}}) return distinct singerGraph")
    List<SingerGraph> querySingerListBySongId(@Param("songId") Integer songId);
}
